package com.work.washer.controller;

import com.work.washer.model.User;
import com.work.washer.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 控制层。
 *
 * @author mybatis-flex-helper automatic generation
 * @since 1.0
 */
@Tag(name = "维修员")
@RestController
@RequestMapping("/sys_user")
public class SysUserController {

    @Autowired
    private UserService userService;

    /**
     * 登录
     * 添加
     *
     * @param user 用户
     * @return {@link User}
     */
    @Operation(summary = "登录或注册，登陆只需要手机号")
    @PostMapping("/login")
    public User login(@RequestBody User user) {
        user.setType(2);
        return userService.login( user);
    }


    /**
     * 根据主键更新
     *
     * @param user
     * @return {@code true} 更新成功，{@code false} 更新失败
     */
    @Operation(summary = "更新信息，头像存base64")
    @PostMapping("/update")
    public boolean update(@RequestBody User user) {
        return userService.updateById(user);
    }


    /**
     * 根据主键获取详细信息。
     *
     * @param id user主键
     * @return 详情
     */
    @Operation(summary = "获取个人信息")
    @GetMapping("/getInfo/{id}")
    public User getInfo(@PathVariable Integer id) {
        return userService.getById(id);
    }


}